package com.example.pulsar.controller;

import com.example.pulsar.service.ConsumersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.PulsarClientException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: 141040
 * @Date: 3/25/2019 10:56
 * @Description:
 */
@Api(tags = "Pulsar消费者控制器", description = "Pulsar消费者控制器")
@RestController
public class ConsumersController {

    @Autowired
    private ConsumersService consumersService;

    @ApiOperation(value = "Pulsar消费者请求方法", notes = "Pulsar消费者请求方法")
    @GetMapping(value = "/createConsumer")
    public String createConsumer() {
        String message;
        try {
            Consumer result = consumersService.createConsumers();
            message = "Pulsar信息接收成功,内如为:" + result;
        } catch (PulsarClientException e) {
            message = "Pulsar信息接收异常,信息如:" + e.getMessage();
        }
        return message;
    }

}
